Section 1.4, Problem 4

x[n] and y[n] are the populations of mouse and owl, respectively,  in the year n. years will be the number of years we run the model for. Initial sizes of the two population will be called initialowl and initialmouse. The coefficient of mouse in the first equation is a.  The coefficient of mouse owl product in the first equation is b. The coefficient of owl in the second equation is c.  The coefficient of mouse owl product in the second equation is d.

years=40
initialowl=150
initialmouse=200
a=1.2
b=-0.001
c=0.7
d=0.002

modelpop=RecurrenceTable[{x[n+1]==a x[n] + b y[n] x[n],y[n+1]==c y[n]+d y[n] x[n],x[0]==initialmouse,y[0]==initialowl},
{x,y},{n,0,years}]

To get a nice table, add // Grid.

modelpop//Grid

To plot the above ordered pairs, do the following. The horizontal axes represents the population of mouse and the vertical axes represents the population of owl.

ListPlot[modelpop, PlotRange->All]

There are years plus one ordered pairs in the modelpop. To get the first element of, say, the fifth ordered pair use modelpop[[5,1]]. To get the second element of, say, the seventh ordered pair use modelpop[[7,2]].

To build ordered pairs of each population size versus year, do the following. Notice that these are years plus one ordered pairs.

mousepop=Table[{i-1, modelpop[[i,1]]},{i,1,years+1}]

owlpop=Table[{i-1, modelpop[[i,2]]},{i,1,years+1}]

Now, we can plot each population separately, or together on the same coordinate system, as done below.

ListPlot[{mousepop,owlpop},PlotStyle->{{Blue, PointSize[0.02]},{Red,PointSize[0.015]}}, PlotRange->All]

Section 1.4, Problem 4, Compact Form

x[n] and y[n] are the populations of mouse and owl, respectively,  in the year n. years will be the number of years we run the model for. Initial sizes of the two population will be called initialowl and initialmouse. The coefficient of mouse in the first equation is a.  The coefficient of mouse owl product in the first equation is b. The coefficient of owl in the second equation is c.  The coefficient of mouse owl product in the second equation is d.

years=40;
initialmouse=150;
initialowl=200;
a=1.2;
b=-0.001;
c=0.7;
d=0.002;
modelpop=RecurrenceTable[{x[n+1]==a x[n] + b y[n] x[n],y[n+1]==c y[n]+d y[n] x[n],x[0]==initialmouse,y[0]==initialowl},
{x,y},{n,0,years}];
modelpop//Grid
ListPlot[modelpop, PlotRange->All]
mousepop=Table[{i-1, modelpop[[i,1]]},{i,1,years+1}];
owlpop=Table[{i-1, modelpop[[i,2]]},{i,1,years+1}];
ListPlot[{mousepop,owlpop},PlotStyle->{{Blue, PointSize[0.02]},{Red,PointSize[0.015]}}, PlotRange->All]

Section 1.4, Problem 7

x[n] and y[n] are the populations of cottony-cushion insect and ladybird beetle, respectively,  in the year n. years will be the number of years we run the model for. Initial sizes of the two population will be called initialcc and initialbeetle. The coefficient of cottony-cushion  in the first equation is 1+k1.  The coefficient of cottony-cushion ladybird beetle product in the first equation is -k2. The coefficient of ladybird beetle in the second equation is 1-k3.  The coefficient of cottony-cushion ladybird beetle product in the second equation is k4. Let h be the kill rate of either insect by DDT.

years=10
initialcc=150
initialbeetle=200
k1=0.2
k2=0.001
k3=0.3
k4=0.002
h=0

modelpop=RecurrenceTable[{x[n+1]==(1+k1-h) x[n] - k2 y[n] x[n],y[n+1]==(1-k3-h) y[n]+k4 y[n] x[n],x[0]==initialcc,y[0]==initialbeetle},
{x,y},{n,0,years}]

To get a nice table, add // Grid.

modelpop//Grid

To plot the above ordered pairs, do the following. The horizontal axes represents the population of cottony-cushion insect and the vertical axes represents the population of ladybird beetle.

ListPlot[modelpop, PlotRange->All]

There are years plus one ordered pairs in the modelpop. To get the first element of, say, the fifth ordered pair use modelpop[[5,1]]. To get the second element of, say, the seventh ordered pair use modelpop[[7,2]].

To build ordered pairs of each population size versus year, do the following. Notice that there are years plus one ordered pairs.

ccpop=Table[{i-1, modelpop[[i,1]]},{i,1,years+1}]

beetlepop=Table[{i-1, modelpop[[i,2]]},{i,1,years+1}]

Now, we can plot each population separately or together on the same coordinate system, as done below.

ListPlot[{ccpop, beetlepop},PlotStyle->{{Red, PointSize[0.02]},{Blue,PointSize[0.015]}}, PlotRange->All]

Section 1.4, Problem 7, Compact Form

x[n] and y[n] are the populations of cottony-cushion insect and ladybird beetle, respectively,  in the year n. years will be the number of years we run the model for. Initial sizes of the two population will be called initialcc and initialbeetle. The coefficient of cottony-cushion  in the first equation is 1+k1.  The coefficient of cottony-cushion ladybird beetle product in the first equation is -k2. The coefficient of ladybird beetle in the second equation is 1-k3.  The coefficient of cottony-cushion ladybird beetle product in the second equation is k4. Let h be the kill rate of either insect by DDT.

years=20;initialcc=150;initialbeetle=200;k1=0.2;k2=0.001;k3=0.3;k4=0.002;h=0;
NSolve[{x==(1+k1-h) x- k2  y x, y==(1-k3-h) y+k4 y  x},{x,y}]
modelpop=RecurrenceTable[{x[n+1]==(1+k1-h) x[n] - k2 y[n] x[n],y[n+1]==(1-k3-h) y[n]+k4 y[n] x[n],x[0]==initialcc,y[0]==initialbeetle},
{x,y},{n,0,years}];
modelpop// Grid
ListPlot[modelpop, PlotRange->All,PlotLabel->"Ladybird versus C-C"]
ccpop=Table[{i-1, modelpop[[i,1]]},{i,1,years+1}];
beetlepop=Table[{i-1, modelpop[[i,2]]},{i,1,years+1}];
ListPlot[{ccpop, beetlepop},PlotStyle->{{Red, PointSize[0.02]},{Blue,PointSize[0.015]}}, PlotRange->All,PlotLabel->"C-C (in red) and Ladybird (in blue) versus Year"]

SIR Model

S[n]: Susceptible
 Inf[n]: Infected are the populations of mouse and owl, respectively,  in the R[n]: Removed
 a: Susceptible to Infected conversion rate
 b: Length of infection in weeks

weeks=25;
initialsusceptible=995;
initialinfected=5;
initialremoved=0;
a=.001407;
b=5/3;
modelpop=RecurrenceTable[{S[n+1]==S[n] - a  Inf[n] S[n],Inf[n+1]==Inf[n]-1/b Inf[n]+a  Inf[n] S[n],
R[n+1]==R[n]+1/b Inf[n],
S[0]==initialsusceptible,
Inf[0]==initialinfected,
R[0]==initialremoved},
{S,Inf,R},{n,0,weeks}];
modelpop// Grid
Spop=Table[{i-1, modelpop[[i,1]]},{i,1,weeks+1}];
Infpop=Table[{i-1, modelpop[[i,2]]},{i,1,weeks+1}];
Rpop=Table[{i-1, modelpop[[i,3]]},{i,1,weeks+1}];
ListPlot[{Spop, Infpop, Rpop},PlotStyle->{{Green, PointSize[0.02]},{Red, PointSize[0.02]},{Blue,PointSize[0.015]}}, PlotRange->All,PlotLabel->"Susc (in green), Infec (in red) and Removed(in blue) versus weeks"]